<?php

namespace IMT\UserBundle\Entity;
use FOS\UserBundle\Entity\User as BaseUser;
use Doctrine\ORM\Mapping as ORM;
use FOS\UserBundle\Model\GroupableInterface;
use Symfony\Component\Validator\Constraints as Assert;

/**
 * @ORM\Entity
 */
class User extends BaseUser
{
    /**
    * @ORM\Id
    * @ORM\Column(type="integer")
    * @ORM\generatedValue(strategy="AUTO")
    */
    protected $id;

    /**
     * @ORM\ManyToMany(targetEntity="IMT\UserBundle\Entity\Group")
     * @ORM\JoinTable(name="fos_user_user_group",
     *      joinColumns={@ORM\JoinColumn(name="user_id", referencedColumnName="id")},
     *      inverseJoinColumns={@ORM\JoinColumn(name="group_id", referencedColumnName="id")}
     * )
     */
    protected $groups;
    
    /**
     * @ORM\OneToMany(targetEntity="IMT\AccountBundle\Entity\Account", mappedBy="user")
     */
    private $accounts;
    
    /**
     * @ORM\OneToOne(targetEntity="IMT\UserBundle\Entity\Participant", mappedBy="user", cascade={"persist"})
     */
    private $participant;

    /**
     * Get id
     *
     * @return integer 
     */
    public function getId()
    {
        return $this->id;
    }
    
/**
     * get expired
     *
     * Implements AdvancedUserInterface
     *
     * @return Boolean true if the user's account is non expired, false otherwise
     */
    public function getTimeExpired()
    {
    	if (null !== $this->expiresAt)
        	return date('d/m/Y',$this->expiresAt->getTimestamp());
        return 'non défini';
    }
    
	/**
     * Checks whether the user's account is going to expired.
     *
     * Implements AdvancedUserInterface
     *
     * @return Boolean true if the user's account is going expired, false otherwise
     */
    public function isAccountGoingExpired()
    {
        if (null !== $this->expiresAt) {
            return true;
        }

        return false;
    }

    /**
     * Checks whether the user is locked.
     *
     * Implements AdvancedUserInterface
     *
     * @return Boolean true if the user is not locked, false otherwise
     */
    public function isAccountNonLocked()
    {
        return !$this->locked;
    }
    public function __construct()
    {
        $this->groups = new \Doctrine\Common\Collections\ArrayCollection();
    }
    
    /**
     * Add groups
     *
     * @param IMT\UserBundle\Entity\Group $groups
     */
    public function addGroupe(\IMT\UserBundle\Entity\Group $groups)
    {
        $this->groups[] = $groups;
    }

    /**
     * Get groups
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getGroups()
    {
        return $this->groups;
    }

//     /**
//      * Add groups
//      *
//      * @param GroupableInterface $groups
//      */
//     public function addGroup(GroupableInterface $groups)
//     {
//         $this->groups[] = $groups;
//     }

    /**
     * Set salt
     *
     * @param String
     */
    public function setSalt($salt)
    {
    	$this->salt = $salt;
    }
    
    /**
     * Set participant
     *
     * @param IMT\UserBundle\Entity\Participant $participant
     */
    public function setParticipant(\IMT\UserBundle\Entity\Participant $participant)
    {
        $this->participant = $participant;
    }

    /**
     * Get participant
     *
     * @return IMT\UserBundle\Entity\Participant
     */
    public function getParticipant()
    {
        return $this->participant;
    }

//     /**
//      * Add groups
//      *
//      * @param IMT\UserBundle\Entity\Group $groups
//      */
//     public function addGroup(\IMT\UserBundle\Entity\Group $groups)
//     {
//         $this->groups[] = $groups;
//     }

    /**
     * Add accounts
     *
     * @param IMT\AccountBundle\Entity\Account $accounts
     */
    public function addAccount(\IMT\AccountBundle\Entity\Account $accounts)
    {
        $this->accounts[] = $accounts;
    }

    /**
     * Get accounts
     *
     * @return Doctrine\Common\Collections\Collection 
     */
    public function getAccounts()
    {
        return $this->accounts;
    }

    /**
     * Add participant
     *
     * @param IMT\UserBundle\Entity\Participant $participant
     */
    public function addParticipant(\IMT\UserBundle\Entity\Participant $participant)
    {
        $this->participant[] = $participant;
    }
}